import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)
import Login from '@/views/login/index'
import Authredirect from '@/views/redirect/index'
import Page404 from '@/views/404'

/* Layout */
import Layout from '@/layout'
export const pageMap = {}

function assignPages(target, source) {
  for (var k in source) {
    target[k] = source[k]
  }
}
import { firstPageIndex, orderPage, productPage } from './firstPage'
assignPages(pageMap, orderPage)
assignPages(pageMap, productPage)

export const router404 = [{ path: '*', redirect: '/404', hidden: true }]
export const pageIndex = [
  { path: '/login', component: Login, hidden: true },
  { path: '/404', component: Page404, hidden: true },
  {
    path: '/',
    component: Layout,
    hidden: true,
    name: '工作台',
    children: [{
      path: '',
      component: firstPageIndex.index,
      name: '工作台',
      meta: { title: '工作台', icon: 'home', affix: true, noCache: true, activeMenu: '1,1,2,1,1,1,1,' }
    },
    {
      path: '/authredirect',
      component: Authredirect,
      hidden: true,
      meta: { title: '', icon: 'home', affix: true, noCache: true, activeMenu: '1,1,2,1,1,1,1,' }
    }
    ]
  }
]

const createRouter = () => new Router({
  scrollBehavior: () => ({ y: 0 }),
  mode: process.env['NODE_ENV'] === 'production' ? 'history' : '',
  base: process.env['NODE_ENV'] === 'production' ? '/pc' : '',
  routes: pageIndex
})
const router = createRouter()
export default router
